unit UfrmClientCollect;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, RzButton, RzEdit, StdCtrls, Mask, RzLabel, ExtCtrls, RzPanel,
  DBGridEhGrouping, DB, ADODB, GridsEh, DBGridEh, QExport3Dialog, frxClass,
  frxDBSet, frxADOComponents, frxDesgn, RzCmboBx, RzDBCmbo;

type
  TfrmClientCollect = class(TForm)
    RzPanel1: TRzPanel;
    RzLabel1: TRzLabel;
    RzLabel2: TRzLabel;
    RzLabel3: TRzLabel;
    dteBegin: TRzDateTimeEdit;
    dteEnd: TRzDateTimeEdit;
    RzEdit1: TRzEdit;
    RzBitBtn1: TRzBitBtn;
    RzStatusBar1: TRzStatusBar;
    DBGridEh1: TDBGridEh;
    qry1: TADOQuery;
    ds1: TDataSource;
    RzButton1: TRzButton;
    RzButton2: TRzButton;
    QExport3Dialog1: TQExport3Dialog;
    wdstrngfldqry1DepotName: TWideStringField;
    intgrfldqry1OrderID: TIntegerField;
    wdstrngfldqry1OrderSign: TWideStringField;
    wdstrngfldqry1OrderType: TWideStringField;
    wdstrngfldqry1OrderNumber: TWideStringField;
    intgrfldqry1EmptyAmount: TIntegerField;
    intgrfldqry1FullAmount: TIntegerField;
    qry1OrderDate: TDateTimeField;
    wdstrngfldqry1ProductName: TWideStringField;
    wdstrngfldqry1ClientName: TWideStringField;
    intgrfldqry1ClientID: TIntegerField;
    intgrfldqry1CurrentAmount: TIntegerField;
    RzButton3: TRzButton;
    frxReport1: TfrxReport;
    frxDBDataset1: TfrxDBDataset;
    frxADOComponents1: TfrxADOComponents;
    frxDesigner1: TfrxDesigner;
    RzLabel4: TRzLabel;
    cbProduct: TRzComboBox;
    qry1price: TFloatField;
    qry1totalsum: TFloatField;
    procedure RzBitBtn1Click(Sender: TObject);
    procedure RzButton2Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure RzButton1Click(Sender: TObject);
    procedure RzButton3Click(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    FclientID:integer;
  public
    { Public declarations }
  end;

var
  frmClientCollect: TfrmClientCollect;

implementation

uses UdataModel, UfrmClientSeacher;

{$R *.dfm}

procedure TfrmClientCollect.RzBitBtn1Click(Sender: TObject);
begin
   with TfrmClientSearch.Create(nil) do
   begin
        try
          ShowModal;
          FclientID:=Clientid;
          RzEdit1.Text:=ClientName;
        finally
           Free;
        end;

   end;
end;

procedure TfrmClientCollect.RzButton2Click(Sender: TObject);
begin
   QExport3Dialog1.Execute;
end;

procedure TfrmClientCollect.FormClose(Sender: TObject;
  var Action: TCloseAction);
begin
   Action:=caFree;
end;

procedure TfrmClientCollect.RzButton1Click(Sender: TObject);
begin
  


   qry1.Close;
   qry1.SQL.Clear;
   qry1.SQL.Add(Format('select  *  from clientcollect where  orderdate  between #%s# ',[DateToStr(dteBegin.Date)] ));
   qry1.SQL.Add(Format(' and  #%s# ',[DateToStr(dteEnd.Date)] ));
   if FclientID > 0 then
   begin
   qry1.SQL.Add(' and clientid=:clientid');
   qry1.Parameters.ParamByName('clientid').Value:=FclientID;
   end;
   if Trim(cbProduct.Text)<>'' then
   begin
      qry1.SQL.Add(' and productname=:productname');
      qry1.Parameters.ParamByName('productname').Value:=Trim(cbProduct.Text);
   end;

   qry1.Open;




end;

procedure TfrmClientCollect.RzButton3Click(Sender: TObject);
begin
   frxReport1.DesignReport();
end;

procedure TfrmClientCollect.FormShow(Sender: TObject);
   var qry:TADOQuery;
begin
   qry:=TADOQuery.Create(nil);
   qry.Connection:=dm.conn;
   try

   qry.SQL.Text:='select * from product';
   qry.Open;

   cbProduct.Items.Clear;
   with qry do
   begin
     Active:=true;
     while not Eof do
     begin
        cbProduct.Items.Add(fieldbyname('productname').AsString);
        Next;
     end;
   end;
   finally
     qry.Free;
   end;  


end;

end.
